PELICAN=./localpelican.sh
PELICANOPTS=

BASEDIR=$(CURDIR)
INPUTDIR=$(BASEDIR)/content
OUTPUTDIR=$(BASEDIR)/output
CONFFILE=$(BASEDIR)/pelicanconf.py
PUBLISHCONF=$(BASEDIR)/publishconf.py

SSH_HOST=mediagoblin.org
SSH_PORT=22
SSH_USER=systems
SSH_TARGET_DIR=/var/www/mediagoblin.org/pelican_build/
SSH_GIT_DIR=/var/www/mediagoblin.org/git_checkout/

STAGING_SSH_TARGET_DIR=/var/www/staging.mediagoblin.org/pelican_build/
STAGING_SSH_GIT_DIR=/var/www/staging.mediagoblin.org/git_checkout/


compile_and_run: html serve

help:
	@echo 'Makefile for a pelican Web site                                        '
	@echo '                                                                       '
	@echo 'Usage:                                                                 '
	@echo '   make virtualenv                  make a virtualenv in place         '
	@echo '   make html                        (re)generate the web site          '
	@echo '   make clean                       remove the generated files         '
	@echo '   make regenerate                  regenerate files upon modification '
	@echo '   make serve                       serve site at http://localhost:8000'
	@echo '   make rsync_upload                upload the web site via rsync+ssh  '
	@echo '   make compile_and_run             compiles html then runs serve      '
	@echo '                                                                       '


virtualenv:
	virtualenv .
	./bin/easy_install -U docutils pelican PasteDeploy PasteScript typogrify

outputdir:
	mkdir -p $(OUTPUTDIR)

html: outputdir clean $(OUTPUTDIR)/index.html
	@echo 'Done'

$(OUTPUTDIR)/%.html:
	$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)

clean:
	find $(OUTPUTDIR) -mindepth 1 -delete

regenerate: clean
	$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)

serve:
	./runserver.sh

upload: html
	rsync --checksum -e "ssh -p $(SSH_PORT)" -P --delete -rvz $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude
	ssh $(SSH_USER)@$(SSH_HOST) "cd $(SSH_GIT_DIR) && git pull && git reset --hard origin/master"

rsync_upload: upload

staging_upload: html
	rsync --checksum -e "ssh -p $(SSH_PORT)" -P --delete -rvz $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(STAGING_SSH_TARGET_DIR) --cvs-exclude
	ssh $(SSH_USER)@$(SSH_HOST) "cd $(STAGING_SSH_GIT_DIR) && git pull && git reset --hard origin/campaign2014"

.PHONY: html help clean regenerate serve rsync_upload upload staging_upload
